/** @file               sw_sem.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: flyfish $
 *  @version            $Rev: 385 $
 *  @date               $Date: 2016-12-22 00:12:05 +0800 (周四, 22 12月 2016) $
 */
#ifndef __SW_SEM_H__
#define __SW_SEM_H__

#ifndef WIN32
#include <semaphore.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifdef WIN32
typedef HANDLE SW_SEM;
#define SW_INVALID_SEM  (SW_SEM)NULL
#else
typedef SW_VOID *SW_SEM;
#define SW_INVALID_SEM  (SW_SEM)NULL
#endif

typedef SW_VOID *SW_BSEM;
#define SW_INVALID_BSEM (SW_BSEM)NULL

SW_API SW_RET SW_InitSemAPI(SW_VOID);
SW_API SW_RET SW_RunSemAPI(SW_VOID);
SW_API SW_RET SW_StopSemAPI(SW_VOID);
SW_API SW_RET SW_ExitSemAPI(SW_VOID);
SW_API SW_SEM SW_OpenSem(const SW_CHAR *pName, SW_OPEN_FLAG flag, SW_UINT32 value);
SW_API SW_RET SW_CloseSem(SW_SEM sem, SW_BOOL unnamed);
SW_API SW_RET SW_DeleteSem(const SW_CHAR *pName);
SW_API SW_RET SW_WaitSem(SW_SEM sem);
SW_API SW_RET SW_TryWaitSem(SW_SEM sem);
SW_API SW_RET SW_TimeWaitSem(SW_SEM sem, SW_UINT32 msec);
SW_API SW_RET SW_PostSem(SW_SEM sem);
SW_API SW_UINT32 SW_GetSemValue(SW_SEM sem);
SW_API SW_BSEM SW_CreateBsem(SW_VOID);
SW_API SW_RET SW_DeleteBsem(SW_BSEM bsem);
SW_API SW_RET SW_WaitBsem(SW_BSEM bsem);
SW_API SW_RET SW_TryWaitBsem(SW_BSEM bsem);
SW_API SW_RET SW_TimeWaitBsem(SW_BSEM bsem, SW_UINT32 msec);
SW_API SW_RET SW_PostBsem(SW_BSEM bsem);
SW_API SW_RET SW_BroadcastBsem(SW_BSEM bsem);

#ifdef __cplusplus
}
#endif

#endif

